package com.vancouver.knows;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.SystemClock;
import android.support.v4.app.NotificationCompat;

import com.google.android.gms.gcm.GcmListenerService;
import com.vancouver.knows.business.bean.PushInfo;
import com.vancouver.knows.ui.activity.citydiscount.CityDiscountDetailActivity;
import com.vancouver.knows.ui.activity.citynews.CityNewsCommentsActivity;
import com.vancouver.knows.ui.activity.citynews.CityNewsDetailActivity;
import com.vancouver.knows.ui.activity.userpost.UserPostDetailActivity;
import com.vancouver.knows.util.AppUtils;

/**
 * 接受push消息
 * 
 * @author chenxunlin01
 * 
 */
public class VghGcmListenerService extends GcmListenerService {

//	@Override
//	public void onMessageReceived(String from, Bundle data) {
//		final PushInfo pushInfo = new PushInfo();
//		pushInfo.setId(data.getString("notification_id"));
//		pushInfo.setPostId(data.getString("post_id"));
//		pushInfo.setCategory(data.getString("category"));
//		pushInfo.setCommentId(data.getString("comment_id"));
//		pushInfo.setMessage(data.getString("message"));
//		pushInfo.setTargetPostType(data.getString("target_post_type"));
//		generateNotification(this, pushInfo);
//	}
//
//	/**
//	 * Issues a notification to inform the user that server has sent a message.
//	 */
//	private static void generateNotification(Context context, PushInfo pushInfo) {
//		Intent intent = new Intent();
//		if ("post".equals(pushInfo.getCategory())) {
//			intent.setClass(context, UserPostDetailActivity.class);
//			intent.putExtra(UserPostDetailActivity.JUMP_TYPE_EXTRA, UserPostDetailActivity.JUMP_TYPE_MY_COMMENT);
//			intent.putExtra(UserPostDetailActivity.POST_ID_EXTRA, pushInfo.getPostId());
//
//		} else if ("comment".equals(pushInfo.getCategory())) {
//			intent.setClass(context, CityNewsCommentsActivity.class);
//			intent.putExtra("postId", pushInfo.getPostId());
//			intent.putExtra("from_my_comment", "from_my_comment");
//
//		} else if ("business".equals(pushInfo.getCategory())) {
//			intent.setClass(context, CityDiscountDetailActivity.class);
//			intent.putExtra("postId", pushInfo.getPostId());
//
//		} else if ("news_detail".equals(pushInfo.getCategory())) {
//			intent.setClass(context, CityNewsDetailActivity.class);
//			intent.putExtra("postId", pushInfo.getPostId());
//		}
//
//		intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
//		intent.setPackage(context.getPackageName());
//		PendingIntent pendingIntent = PendingIntent.getActivity(context, (int) SystemClock.elapsedRealtime(), intent,
//				PendingIntent.FLAG_UPDATE_CURRENT);
//		NotificationCompat.Builder build = new NotificationCompat.Builder(context)
//				.setSmallIcon(R.drawable.notication_icon).setTicker(pushInfo.getMessage())
//				.setContentTitle(context.getResources().getString(R.string.app_name))
//				.setContentText(pushInfo.getMessage()).setWhen(System.currentTimeMillis()).setAutoCancel(true)
//				.setContentIntent(pendingIntent);
//		if (!AppUtils.isDoNotDisturb()) {
//			build.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE);// 铃声、震动均系统默认。
//		}
//		Notification notification = build.build();
//		NotificationManager notificationManager = (NotificationManager) context
//				.getSystemService(Context.NOTIFICATION_SERVICE);
//		notificationManager.notify(pushInfo.getId().hashCode(), notification);
//	}

}
